package com.example.customviewprojdct.activity.class_package

import android.content.Context
import android.content.Intent
import android.graphics.Color
import android.view.View
import android.widget.FrameLayout
import com.example.customviewprojdct.activity.BaseClassActivity
import com.example.customviewprojdct.extensions.dp
import com.example.customviewprojdct.view.class1.DashboardView
import com.example.customviewprojdct.view.class1.PieView
import com.example.customviewprojdct.view.class1.SinglePieView
import com.example.customviewprojdct.view.class1.TestView
import com.example.customviewprojdct.view.other.DashboardProgressView
import com.example.customviewprojdct.view.other.IslandAvatarView
import com.example.customviewprojdct.view.other.PwdStrongView
import com.example.customviewprojdct.view.other.RectProgressView
import com.example.customviewprojdct.view.other.RelativeProgressView
import com.example.customviewprojdct.view.other.ScheduleView

class ClassOneActivity : BaseClassActivity() {
    companion object {
        fun start(context: Context) {
            context.startActivity(Intent(context, ClassOneActivity::class.java))
        }
    }

    override fun initData(): MutableList<Triple<String, String, Class<out View>?>> {
        return mutableListOf(
            Triple("1", "测试", TestView::class.java),
            Triple("2", "仪表盘", DashboardView::class.java),
            Triple("3", "饼图", PieView::class.java),
            Triple("4", "矩形进度", RectProgressView::class.java),
            Triple("5", "圆形进度", DashboardProgressView::class.java),
            Triple("6", "日程表", ScheduleView::class.java),
            Triple("7", "默认文字图", IslandAvatarView::class.java),
            Triple("8", "密码强度", PwdStrongView::class.java),
            Triple("9", "简单饼图", SinglePieView::class.java),
            Triple("10", "相对进度", RelativeProgressView::class.java)
        )
    }

    override fun onButtonItemExtraEvent(view: View) {
        when(view){
            is SinglePieView -> {
                view.setData(
                    arrayListOf(
                        SinglePieView.PieItem(1, Color.RED, 5),
                        SinglePieView.PieItem(2, Color.GREEN, 90),
                        SinglePieView.PieItem(3, Color.YELLOW, 5)
                    )
                )
            }
            is RectProgressView ->{
                val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
//                val params = FrameLayout.LayoutParams(200.dp.toInt(), 12.dp.toInt())
                view.layoutParams = params

                view.postDelayed({
//                    view.rectCount = 2
                    view.setProgress(80f, true)
                                 },1000)
            }
            is DashboardProgressView -> {
                val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
                view.layoutParams = params

                view.postDelayed({
//                    view.rectCount = 2
                    view.setProgress(80f, true)
                },1000)
            }
            is ScheduleView -> {
                val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.WRAP_CONTENT, FrameLayout.LayoutParams.WRAP_CONTENT)
                view.layoutParams = params
                view.addOtherSchedule(7.3f, 10f)
                view.addOtherSchedule(11f, 12f)
                view.addMySchedule(16f, 18.8f)
                view.addMySchedule(20f, 24f)
                view.notifyChange()
//                view.postDelayed({
//                    view.clearSchedule()
//                    view.addOtherSchedule(7f, 25f)
//                    view.notifyChange()
//                }, 2000)
            }
            is IslandAvatarView -> {
                view.setBackgroundColor(Color.parseColor("#55000000"))
                val params = FrameLayout.LayoutParams(200.dp.toInt(), 200.dp.toInt())
                view.layoutParams = params
                view.postDelayed({
                   view.setIslandInfo("https://www.baidu.com", "哈哈")
                }, 2000)
                view.postDelayed({
                    view.setIslandInfo(null, "哈2")
                }, 3000)
                view.postDelayed({
                    view.setIslandInfo("https://www.baidu.com", "哈3")
                }, 5000)
                view.postDelayed({
                    view.setIslandInfo(null, "哈4")
                }, 6000)
//                view.postDelayed({
//                    val params = FrameLayout.LayoutParams(40.dp.toInt(), 40.dp.toInt())
//                    view.layoutParams = params
//                }, 4000)
            }
            is RelativeProgressView -> {
                val params = FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.WRAP_CONTENT)
                view.layoutParams = params

                view.postDelayed({
                    view.startAnimatorProgress(80f, true)
                },1000)
            }
        }
    }

}